﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ManageSystem
{
    public partial class ManageBookType : Form
    {
        public ManageBookType()
        {
            InitializeComponent();
            initData();

        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void initData()
        {
            listView1.Items.Clear();
            SqlDataReader sdr = Utils.getDataReader("select * from bookType");
            while (sdr.Read())
            {

                ListViewItem lv = new ListViewItem(sdr[0].ToString());


                lv.SubItems.Add(sdr[1].ToString());

                listView1.Items.Add(lv);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {

            if (listView1.SelectedItems.Count > 0)
            {
                if (MessageBox.Show("是否要删除当前选中分类?（删除后该分类下所有书籍都将被删除！）", "删除询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    string delStr = "delete from bookType where typeId=" + listView1.SelectedItems[0].SubItems[0].Text;
                    Utils.ExecuteNoQuery(delStr);
                    delStr = "delete from bookInfo where bookType=N'" + listView1.SelectedItems[0].SubItems[1].Text + "'";

                    Utils.ExecuteNoQuery(delStr);
                    initData();
                }

            }
        }

        public void updateData()
        {
            initData();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AddType addType = new AddType();
            addType.Owner = this;
            addType.Show();
        }

        private void ManageBookType_Load(object sender, EventArgs e)
        {

        }
    }
}
